import { IMyObject, MyObject } from "./MyObject";
import { IStudent, Student } from "./Student";
import { IMyClass, MyClass } from "./MyClass";
import { Grade, GradeType } from "./Grade";
import { ysReadline, ysReadlineClose } from "../read";

export interface IMenuItem extends IMyObject {
  run(): void;
}

const classes: IMyClass[] = [];
const students: Student[] = [];

export class AddClassMenuItem extends MyObject implements IMenuItem {
  id = 0;

  toString(): string {
    return "添加班级";
  }

  run(): void {
    console.log("添加班级");

    classes.push(new MyClass(this.id));

    this.id++;

    classes.forEach((item) => {
      console.log(item.name);
    });
  }
}

export class AddStudentsMenuItem extends MyObject implements IMenuItem {
  id = 0;

  toString(): string {
    return "添加学生";
  }

  async run() {
    classes.forEach((item, index) => {
      console.log(`${index}: ${item.toString()}`);
    });

    let msg = await ysReadline("请输入序号：");
    const c = classes[Number(msg)];

    msg = await ysReadline("请输入学生姓名：");
    c.addStudent(new Student(this.id, msg));
    this.id++;
  }
}

export class ShowClassedGradeMenuItem extends MyObject implements IMenuItem {
  id = 0;
  name = "打印所有班级的成绩";

  async run() {
    classes.forEach((item, index) => {
      item.showGrade();
    });
  }
}
